//
//  WBHomeViewController.m
//  TransWB
//
//  Created by 孝飞王 on 2016/12/27.
//  Copyright © 2016年 孝飞王. All rights reserved.
//

#import "WBHomeViewController.h"
#import "WBStatusListModelView.h"
#import "WBTitleView.h"

static  NSString *cellId = @"WBHomeViewControllerCell";

@interface WBHomeViewController ()

@property (nonatomic,strong)WBStatusListModelView *statusListViewModel;
@end

@implementation WBHomeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [WBNetworkManager shareManager].isLogin ? [self setUpNavigationItem] : [self setRegestNavItem];
    
    //设置标题
    [self setTieleView];
}

- (void)setRegestNavItem{
    
    //登录注册应该是通知的时候 就应该来发通知  任何时候任何地方都会是需要登录注册的
    self.navItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton cz_titleAndImage:nil title:@"注册" taget:self action:@selector(compauseRegester)]];
    self.navItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton cz_titleAndImage:nil title:@"登录" taget:self action:@selector(compauseLogin)]];
    self.navBar.tintColor = [UIColor orangeColor];
    
}

//登录按钮
-(void)compauseLogin{
     [[NSNotificationCenter defaultCenter] postNotificationName:ShouldLoginSuccess object:nil];
}


//登录后的结果
- (void)setUpNavigationItem{
    
    self.navBar.tintColor = [UIColor darkGrayColor];
    self.navItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton cz_titleAndImage:nil title:@"好友" taget:self action:@selector(leftItemClick)]];
}


- (void)setUpTabelView{
    [super setUpTabelView];
    
    [self.baseTabaleView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellID"];
    
}

#pragma mark - LoadData
- (void)loadData{
    
    [self.statusListViewModel loadStatusIsPull:isPull isSuccess:^(BOOL isSuccess) {
        isPull = NO;
        self.dataSourceArray = self.statusListViewModel.statusDataSource;
        [self.baseTabaleView reloadData];
        [self.refreshControl endRefreshing];
    }];
    
}


//左边按钮点击
- (void)leftItemClick{
    
    UIViewController *vc = [[NSClassFromString(@"WBTestViewController") alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - 设置标题属性
- (void)setTieleView{
    
    WBTitleView *btn = [[WBTitleView alloc]init];
    [btn addTarget:self action:@selector(btnClickUpDown:) forControlEvents:UIControlEventTouchUpInside];
    self.navItem.titleView = btn;
}

- (void)btnClickUpDown:(UIButton*)btn{
    btn.selected = !btn.isSelected;
}

#pragma mark - LazyLoad -- ViewModel
- (WBStatusListModelView *)statusListViewModel{
    
    if(_statusListViewModel == nil)
        _statusListViewModel = [WBStatusListModelView new];
    return _statusListViewModel;
}

@end






